import request from "@/utils/request";

// 注册
export const userRegisterService = (registerData) => {
    let params = new URLSearchParams()
    for (let key in registerData) {
        params.append(key, registerData[key])
    }
    return request.post("/user/register", params);
}
// 登录
export const userLoginService = (loginData) => {
    let params = new URLSearchParams()
    for (let key in loginData) {
        params.append(key, loginData[key])
    }
    return request.post("/user/login", params);
}
// 获取用户详细信息
export const userInfoService = () => {
    return request.get('/user/user-info');
}

// 更新用户信息
export const userInfoUpdateService = (user) => {
    return request.put('/user', user)
}
// 更新密码
export const userInfoUpdatePasswordService = (params) => {
    return request.patch("/user/update-password", params)
}
// 更新头像信息
export const userInfoUpdateAvatarService = (avatarUrl) => {
    let params = new URLSearchParams()
    params.append('avatarUrl', avatarUrl)
    return request.patch('/user/update-avatar', params)
}

// 获取所有用户分页信息
export const userListPageService = (param) => {
    return request.get('/user/page', { params: param })
}
// 新增用户
export const userAddService = (param) => {
    return request.post('/user', param)
}
// 更新用户
export const userUpdateService = (param) => {
    return request.put('/user', param)
}
// 删除用户
export const userDeleteService = (id) => {
    return request.delete('/user/' + id)
}
// 批量删除
export const userDeleteBatchService = (ids) => {
    return request.delete('/user/delete-batch',{ data: ids })
}

// 获取所有管理员分页数据
export const adminListPageService = (param) => {
    return request.get('/admin/page', { params: param })
}
// 新增管理员
export const adminAddService = (param) => {
    return request.post('/admin', param)
}
// 更新管理员
export const adminUpdateService = (param) => {
    return request.put('/admin', param)
}
// 删除管理员
export const adminDeleteService = (id) => {
    return request.delete('/admin/' + id)
}
// 批量删除
export const adminDeleteBatchService = (ids) => {
    return request.delete('/admin/delete-batch',{ data: ids })
}